/**
 * 微信 stat schema
 */
var Schema = require('mongoose').Schema,
    wechatStatSchema;
var ObjectId = require('mongoose').Types.ObjectId;

wechatStatSchema = new Schema({
    "stat_time": String,
    'keyword_id':String,
    'title':String,
    //微信正负向 (正向+负向+中立)
    "wechat_tendency": [
        {
            "positive": Number,
            "negative": Number,
            "neutral": Number
        }
    ],

    //微信阅读量/点赞量 （日期+阅读量+点赞量）
    "wechat_playlike": [{
        "date": String,
        "read_num": Number,
        "like_num": Number
    }],
    //微博指数关联词 （关键词1+关键词2+权重）
    "wechat_relate_words":  [
        {
            "dianshitai": [],
            "shipinwangzhan": [],
            "jiemu": [],
            "menhuwangzhan": [],
            "zhuanyemeiti": [],
            "zhimei": [],
            "pinpai": [],
            "zimeiti": []
        }
    ],
    // wechat 词频
    "wechat_top_keywords":[
        {
            "words":[
                {
                    "word":String,
                    "frequency":Number
                }
            ]
        }
    ]

});

wechatStatSchema.statics = {
    savePlaylike : function(keyword_id, title, exportData){
        var insertData = new this({
            'stat_time': Number(String(Date.parse(new Date())).substring(0, 10)),
            'keyword_id': keyword_id,
            'title': title,
            'wechat_playlike': exportData
        });
        insertData.save(insertData, function (err) {
            if (err) {
                console.log(err);
            }
            console.log(title+'  阅读量/点赞量 插入成功');
        });
    },

    saveRelateWords : function(keyword_id, title, exportData){
        var insertData = new this({
            'stat_time': Number(String(Date.parse(new Date())).substring(0, 10)),
            'keyword_id': keyword_id,
            'title': title,
            'wechat_relate_words': exportData
        });
        insertData.save(insertData, function (err) {
            if (err) {
                console.log(err);
            }
            console.log(title+'  关键词 插入成功');
        });
    },

    saveSentiment : function(keyword_id, title, exportData){
        var insertData = new this({
            'stat_time': Number(String(Date.parse(new Date())).substring(0, 10)),
            'keyword_id': keyword_id,
            'title': title,
            'wechat_tendency': exportData
        });
        insertData.save(insertData, function (err) {
            if (err) {
                console.log(err);
            }
            console.log(title+'  倾向性 插入成功');
        });
    },

    saveFrequency : function(keyword_id, title, exportData){
        var insertData = new this({
            'stat_time': Number(String(Date.parse(new Date())).substring(0, 10)),
            'keyword_id': keyword_id,
            'title': title,
            'wechat_top_keywords': exportData
        });
        insertData.save(insertData, function (err) {
            if (err) {
                console.log(err);
            }
            console.log(title+'  词频 插入成功');
        });
    }
};

exports.wechatStatSchema = wechatStatSchema;
